package com.example.thumbsupdemo

import android.animation.TypeEvaluator
import android.util.Log

class RotateAndScaleEvaluator : TypeEvaluator<RotateAndScaleEvaluator.RotateAndScale> {
    private var result = RotateAndScale()

    override fun evaluate(
        fraction: Float,
        startValue: RotateAndScale,
        endValue: RotateAndScale
    ): RotateAndScale {
        Log.d("", "evaluate: start = $startValue, end = $endValue")
        // result = x0 + t * (x1 - x0), where x0 is startValue, x1 is endValue, and t is fraction.
        val rotate = startValue.rotate + fraction * (endValue.rotate - startValue.rotate)
        val scale = startValue.scale + fraction * (endValue.scale - startValue.scale)
        result.rotate = rotate
        result.scale = scale
        return result
    }

    class RotateAndScale() {

        constructor(r: Float, s: Float) : this() {
            rotate = r
            scale = s
        }

        var rotate = 0F
        var scale = 0F
        override fun toString(): String {
            return "[rotate = $rotate, scale = $scale]"
        }
    }
}